package com.fenqing.utils;

import cn.hutool.core.lang.TypeReference;
import cn.hutool.json.JSONUtil;
import com.fenqing.bean.ListNode;

import java.util.List;

/**
 * @author fenqing
 */
public class StringToListNodeEncoder implements Encoder<String, ListNode>{
    @Override
    public ListNode encoder(String input) {
        input = input.trim();
        List<Integer> lists = JSONUtil.toBean(input, new TypeReference<List<Integer>>() {
        }, true);
        ListNode result = new ListNode();
        ListNode now = result;
        for (Integer list : lists) {
            now.next = new ListNode(list);
            now = now.next;
        }
        return result.next;
    }
}
